package cn.edu.scau.cmi.zhangmingxing.client;

import cn.edu.scau.cmi.zhangmingxing.factory.BeefFactory;
import cn.edu.scau.cmi.zhangmingxing.factory.ChickenFactory;
import cn.edu.scau.cmi.zhangmingxing.factory.MeatFactory;
import cn.edu.scau.cmi.zhangmingxing.factory.PorkFactory;
import cn.edu.scau.cmi.zhangmingxing.simpleFactoryMethod.domain.Meat;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class FactoryClient extends Application {
	
		public void start(Stage primaryStage) {
			primaryStage.setTitle("Factory");
			Group root=new Group();
			HBox btn=new HBox();
			btn.setLayoutX(10);
			btn.setLayoutY(10);
			TextArea area=new TextArea();
			area.setLayoutX(10);
			   area.setLayoutY(45);
			   area.setMaxHeight(240);
			   area.setMaxWidth(550);
			   area.setEditable(false);
			Button btn1=new Button();
			btn1.setText("chicken");
			Button btn2=new Button();
			btn2.setText("pork");
			Button btn3=new Button();
			btn3.setText("beef");
			btn.setSpacing(40);
			btn.setAlignment(Pos.CENTER);
			btn1.setOnAction(new EventHandler<ActionEvent>() {
		        @Override
		        public void handle(ActionEvent event) {
		        	MeatFactory meatFactory=new ChickenFactory();
		        	Meat chicken=meatFactory.getMeat();
		        	area.appendText(chicken.cook());
		        }
		    });
			btn2.setOnAction(new EventHandler<ActionEvent>() {
				public void handle(ActionEvent event) {
					MeatFactory meatFactory=new PorkFactory();
		        	Meat pork=meatFactory.getMeat();
		        	area.appendText(pork.cook());
				}
			});
			btn3.setOnAction(new EventHandler<ActionEvent>() {
				public void handle(ActionEvent event) {
					MeatFactory meatFactory=new BeefFactory();
		        	Meat beef=meatFactory.getMeat();
		        	area.appendText(beef.cook());
				}
			});
			btn.getChildren().addAll(btn1,btn2,btn3);
			root.getChildren().addAll(area,btn);
			Scene scene=new Scene(root,600,300,Color.rgb(0, 0, 0,0));
			primaryStage.setScene(scene);
			primaryStage.show();
		}
		public static void main(String[] args) {
			// TODO Auto-generated method stub
			launch(args);
		}

	
}
